;===================================================================================================
;=                                                                                                 =
;=                                 raisusoft iflys start                                           =
;=                                    hspcode                                                      =
;=                                                                                                 =
;===================================================================================================

;ݒ
#define PBS_MARQUEE  0x08
#define PBM_SETMARQUEE 0x040A 
#include "user32.as"
#uselib "user32"
win_w = 1200
win_h = 800

margin = 100

x1 = margin
y1 = margin
x2 = win_w - margin
y2 = win_h - margin

btn_w = 50
btn_h = 50

btn_x = x2 - btn_w
btn_y = y1

calc_text = ""
val1 = 0
valope = ""
is_calc_end = 0

*boot ;boot^OɂƂƂɂčċN\ɂB
;ʎ̐ݒ
screen 0,1200,800
title "iflys start"
wait 20 ;ŏ̋Ỏo
color 0,0,0
boxf
wait 200
;BIOS
color 255,255,255
pos 400,100
font "lr SVbN", 64
mes "BIOS"
pos 500,400
mes "stating iflys,,,"
pos 0,0
button "debuc", *desktop
wait 300
;u[g
cls 0
color 0,150,100
boxf
font "lr SVbN", 32
color 255,255,255
pos 300,500
mes "stating,,,"
winobj "msctls_progress32", "", 0, $50000000 | PBS_MARQUEE, 200, 20
    h=objinfo(stat,2)
sendmsg h,PBM_SETMARQUEE,1,0
wait 300
;OC
cls 0
color 170,100
boxf
color 255,255,255
font "lr SVbN", 64
pos 300,200
mes "login"
;pX[h͉ʂ̍쐬
pass_word = ""
input pass_word
objsize 50, 50
button "OK", *pass_check
pos 0,0
button "Vbg_E", *exit
stop

;pX[h`FbN
*pass_check
if pass_word = "0000" :goto *desktop :else :goto *passno
stop


;pX[hꍇ(fXNgbvj
*desktop
    cls
    ; desktop.pngwiƂēǂݍŕ\
    color 0,150,100
    boxf
    
    ; wȉɕACRuꍇ͂ɒǉĂ
    color 255, 255, 255
    pos 20, 20
    mes "fXNgbvւ悤I"
    pos 20,50
    button "", *jyouhou
    
    pos 20, 90
    button "d", *calculator

    pos 20, 130
    button "", *memoapp
    
    pos 20, 750
    button "Vbg_E", *exit

    ; === ʂ̉EɃX^[g{^zu ===
    pos win_w - 110, 20
    objsize 90, 40
    button "X^[g", *start_screen
    stop

*subdesktop
    cls
    ; desktop.pngwiƂēǂݍŕ\
    color 0,150,100
    boxf
    
    ; wȉɕACRuꍇ͂ɒǉĂ
    color 255, 255, 255
    pos 20, 20
    mes "fXNgbvւ悤I"
    pos 20,50
    button "", *jyouhou
    
    pos 20, 90
    button "d", *calculator

    pos 20, 130
    button "", *memoapp
    
    pos 20, 750
    button "Vbg_E", *exit

    ; === ʂ̉EɃX^[g{^zu ===
    pos win_w - 110, 20
    objsize 90, 40
    button "X^[g", *start_screen
    return


; ==========================================
; SʃX^[gj[
; ==========================================
*start_screen
    cls
    ; X^[gʗp̔wiF
    color 30, 40, 60
    boxf

    ; ^Cg
    color 255, 255, 255
    font "lr SVbN", 32
    pos 100, 80
    mes "X^[gj["

    ; X^[gʂɕׂAṽ^Ci{^j
    pos 100, 150
    objsize 180, 100
    button "Av", *jyouhou

    pos 300, 150
    objsize 180, 100
    button "d", *calculator

    pos 500, 150
    objsize 180, 100 
    button "", *memoapp

    
    objsize 90, 40
    pos 20, 750
    button "Vbg_E", *exit

    ; fXNgbvɖ߂{^
    pos win_w - 110, 20
    objsize 90, 40
    button "", *desktop
    stop

;pX[hԈĂꍇ
*passno
    dialog "pX[hԈĂ܂", 1, "G["
    stop

*exit
    cls 0
    color 0,150,100
    boxf
    font "lr SVbN", 32
    color 255,255,255
    pos 300,500
    mes "shutdown,,,"
    winobj "msctls_progress32", "", 0, $50000000 | PBS_MARQUEE, 200, 20
        h=objinfo(stat,2)
    sendmsg h,PBM_SETMARQUEE,1,0
    wait 300
    end


*jyouhou
    gosub *subdesktop
    gosub *window
    
    pos x1 + 20, y1 + 15
    color 255,255,255
    mes ""
    pos x1 + 30, y1 + 70
    font "lr SVbN", 32
    mes "PC̖OFiflys start"
    mes "o[WF1.0"
    mes "OSiǂj͎̕"
    mes "ANeBx[gĂ܂B"
    mes " raisusoft,adomin"
    stop
    
*calculator
    gosub *subdesktop
    gosub *window

    ; тɃ^Cg\
    color 255, 255, 255
    font "lr SVbN", 20
    pos x1 + 20, y1 + 15
    mes "d"

    ; d̃fBXvCwi
    color 255, 255, 255
    boxf x1 + 50, y1 + 70, x1 + 330, y1 + 120
    color 0, 0, 0
    font "lr SVbN", 24
    pos x1 + 60, y1 + 78
    mes calc_text

    ; {^zu
    bw = 60 : bh = 50 : bp = 10
    sx = x1 + 50
    sy = y1 + 140

    pos sx + (bw+bp)*0, sy + (bh+bp)*0 : objsize bw, bh : button "7", *c_7
    pos sx + (bw+bp)*1, sy + (bh+bp)*0 : objsize bw, bh : button "8", *c_8
    pos sx + (bw+bp)*2, sy + (bh+bp)*0 : objsize bw, bh : button "9", *c_9
    pos sx + (bw+bp)*3, sy + (bh+bp)*0 : objsize bw, bh : button "{", *c_plus

    pos sx + (bw+bp)*0, sy + (bh+bp)*1 : objsize bw, bh : button "4", *c_4
    pos sx + (bw+bp)*1, sy + (bh+bp)*1 : objsize bw, bh : button "5", *c_5
    pos sx + (bw+bp)*2, sy + (bh+bp)*1 : objsize bw, bh : button "6", *c_6
    pos sx + (bw+bp)*3, sy + (bh+bp)*1 : objsize bw, bh : button "[", *c_minus

    pos sx + (bw+bp)*0, sy + (bh+bp)*2 : objsize bw, bh : button "1", *c_1
    pos sx + (bw+bp)*1, sy + (bh+bp)*2 : objsize bw, bh : button "2", *c_2
    pos sx + (bw+bp)*2, sy + (bh+bp)*2 : objsize bw, bh : button "3", *c_3
    pos sx + (bw+bp)*3, sy + (bh+bp)*2 : objsize bw, bh : button "~", *c_multi

    pos sx + (bw+bp)*0, sy + (bh+bp)*3 : objsize bw, bh : button "0", *c_0
    pos sx + (bw+bp)*1, sy + (bh+bp)*3 : objsize bw, bh : button "C", *c_clr
    pos sx + (bw+bp)*2, sy + (bh+bp)*3 : objsize bw, bh : button "", *c_eq
    pos sx + (bw+bp)*3, sy + (bh+bp)*3 : objsize bw, bh : button "", *c_div
    stop

; --- ꂽƂ ---
*c_7 : gosub *add_num : calc_text += "7" : goto *calculator
*c_8 : gosub *add_num : calc_text += "8" : goto *calculator
*c_9 : gosub *add_num : calc_text += "9" : goto *calculator
*c_4 : gosub *add_num : calc_text += "4" : goto *calculator
*c_5 : gosub *add_num : calc_text += "5" : goto *calculator
*c_6 : gosub *add_num : calc_text += "6" : goto *calculator
*c_1 : gosub *add_num : calc_text += "1" : goto *calculator
*c_2 : gosub *add_num : calc_text += "2" : goto *calculator
*c_3 : gosub *add_num : calc_text += "3" : goto *calculator
*c_0 : gosub *add_num : calc_text += "0" : goto *calculator

*add_num
    if is_calc_end = 1 : calc_text = "" : is_calc_end = 0
    return

; --- ZqꂽƂ ---
*c_plus
    val1 = int(calc_text)  ; ʂɂ镶𐔒lɕςĕۑ
    valope = "+"
    calc_text = ""
    goto *calculator

*c_minus
    val1 = int(calc_text)
    valope = "-"
    calc_text = ""
    goto *calculator

*c_multi
    val1 = int(calc_text)
    valope = "*"
    calc_text = ""
    goto *calculator

*c_div
    val1 = int(calc_text)
    valope = "/"
    calc_text = ""
    goto *calculator

; --- NA ---
*c_clr
    calc_text = "" : val1 = 0 : valope = "" : is_calc_end = 0
    goto *calculator

; --- ivZsj ---
*c_eq
    val2 = int(calc_text)  ; 2߂̐擾
    ans = 0

    ; Zqɍ킹ČvZI
    if valope = "+" : ans = val1 + val2
    if valope = "-" : ans = val1 - val2
    if valope = "*" : ans = val1 * val2
    if valope = "/" {
        if val2 = 0 {
            calc_text = "G["
            is_calc_end = 1
            goto *calculator
        } else {
            ans = val1 / val2
        }
    }

    ; ʂʂɕ\
    calc_text = "" + ans
    is_calc_end = 1
    goto *calculator


; ==========================================
; Avimemo.txtXV^j
; ==========================================
*memoapp
    gosub *subdesktop
    gosub *memowindow

    ; тɃ^Cgƃ^CX^v{^\
    color 255, 255, 255
    font "lr SVbN", 20
    pos x1 + 20, y1 + 15
    mes " (memo.txt)"

    ; ^CX^v}{^
    pos x1 + 200, y1 + 10
    objsize 140, 30
    button "^CX^v", *memo_timestamp

    ;  memo.txt Γǂݍށî݁A܂͕ϐj
    if memo_loaded = 0 {
        exist "memo.txt"
        if strsize >= 0 {
            notesel memo_buf
            noteload "memo.txt"
        } else {
            memo_buf = ""
        }
        memo_loaded = 1
    }

    ; eLXg̓GAisEXN[Ήj
    pos x1 + 20, y1 + 60
    objsize x2 - x1 - 40, y2 - y1 - 120
    mesbox memo_buf, x2 - x1 - 40, y2 - y1 - 120, 1

    ; EsJE^[̕\iA^Cj
    ; mesbox̓e͕ϐ memo_buf ɘAĂ
    notesel memo_buf
    all_lines = stat
    all_chars = strlen(memo_buf)

    color 255, 255, 255
    boxf x1 + 20, y2 - 50, x1 + 300, y2 - 20
    color 0, 0, 0
    font "lr SVbN", 16
    pos x1 + 30, y2 - 42
    mes ": " + all_chars + " / s: " + all_lines + "s"

    stop

; --- ^CX^v} ---
*memo_timestamp
    ; ݂̓擾ătH[}bg
    t_str = "" + gettime(0) + "/" + getpath(str(1+100), 1) + "/" + gettime(3) + " " + gettime(4) + ":" + gettime(5)
    memo_buf += "\n[" + t_str + "]\n"
    goto *memoapp

; --- 鎞Ɏۑ鏈 ---
*memo_save_and_exit
    ; memo.txt ɏ㏑ۑ
    notesel memo_buf
    notesave "memo.txt"
    memo_loaded = 0 ; JƂɍēǂݍ݂ł悤ɃZbg
    goto *desktop

    

;window`֐
*window
    color 0, 128, 255
    boxf x1, y1, x2, y2
    color 0, 0, 0
    boxf x1, y1, x2, y1 + 50
    pos btn_x, btn_y
    objsize btn_w, btn_h
    button "~", *desktop
    return

*memowindow
    color 0, 128, 255
    boxf x1, y1, x2, y2
    color 0, 0, 0
    boxf x1, y1, x2, y1 + 50
    pos btn_x, btn_y
    objsize btn_w, btn_h
    button "~", *memo_save_and_exit
    return